package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.*;

@Getter
@Setter
public class StrategyComment extends BaseDomain{
    //作者
    private User user;
    //创建时间
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;
    //内容
    private String content;
    //图片
    private String imgUrls;
    //星星数量
    private Integer starNum;
    //所评论的攻略
    private Strategy strategy;
    //点赞数
    private int likeNum;
    //评论的状态
    private Integer state = 0 ;//1代表推荐,0代表正常,-1代表禁用
    //推荐的时间
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date commendTime;

    public String getJson() {
        Map<String, Object> map = new HashMap();
        map.put("id", id);
        map.put("state", state);
        return JSONUtil.toJSONString(map);
    }

    public List getImgList() {
        if(imgUrls!=null&&imgUrls!=""){
            String[] split = imgUrls.split(",");

            ArrayList<Object> list = new ArrayList<>();
            for (String s : split) {
                String trim = s.trim();
                list.add(trim);
            }
            return list;
        }
        return null;
    }
    //jrender页面渲染 星星个数的循环
    public List getStarNums(){
        if(starNum!=null&&starNum!=0){
            List<Object> list = new ArrayList<>();
            for (int i = 0; i < starNum; i++) {
                list.add(i);
            }
            return list;
        }
        return null;
    }
    //jrender页面渲染需要
    public List<Map> getImgLists() {
        if(imgUrls!=null&&imgUrls!="") {
            String[] split = imgUrls.split(",");
            ArrayList<Map> list = new ArrayList<>();
            for (String s : split) {
                Map<Object, Object> map = new HashMap<>();
                String trim = s.trim();
                map.put("imgUrls", trim);
                list.add(map);
            }
            return list;
        }
        return null;
    }
}